<template>
  <div class="container">
    <div class="top">集团动态</div>
    <div class="box">
      <div class="top1">
        <div class="left">
          <span>标题：</span>
          <el-input v-model="input1" class="first"></el-input>
          <span>状态：</span>
          <el-select v-model="value" placeholder="请选择" class="second">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
          <span>所属专题：</span>
          <el-select v-model="value4" placeholder="请选择" class="second">
            <el-option v-for="item in list" :key="item.id" :label="item.title" :value="item.id"></el-option>
          </el-select>
          <span>创建日期：</span>
          <el-date-picker
            class="data"
            value-format="yyyy-MM-dd"
            v-model="value1"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
          <el-button type="primary" class="search" @click="search" v-show="_SHOWBTN('wzgl-xsxc-jtdt-ss')">查询</el-button>
          <el-button class="reset" @click="reset">重置</el-button>
        </div>
        <div class="right">
          <el-button type="primary" @click="add" class="add" v-if="_SHOWBTN('wzgl-xsxc-jtdt-xj')">+新建</el-button>
        </div>
      </div>
      <!-- 表格 -->
      <el-table
        :data="tableList"
        style="width:1540px"
        border
        stripe
        :cell-style="changeCellStyle"
        :header-cell-style="rowClass"
      >
        <el-table-column type="index" label="序号" width="52px" align="center"></el-table-column>
        <el-table-column prop="title" label="标题"></el-table-column>
        <el-table-column prop="relationName" label="所属专题" width="240px" align="center"></el-table-column>
        <el-table-column label="状态" width="240px" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.publishStatus === 1">待审核</span>
            <span v-else-if="scope.row.publishStatus === 2">待发布</span>
            <span v-else-if="scope.row.publishStatus === 4">已发布</span>
            <span v-else-if="scope.row.publishStatus === 3">被退回</span>
          </template>
        </el-table-column>
        <el-table-column prop="publishTime" label="发布日期" align="center" width="240px"></el-table-column>
        <el-table-column prop="opTime" label="创建日期" align="center" width="240px"></el-table-column>
        <el-table-column label="操作" align="center" width="223px">
          <template slot-scope="scope">
            <el-button size="small" class="five" @click="look1(scope.row.id)"  v-show="_SHOWBTN('wzgl-xsxc-jtdt-ck')">查看</el-button>
            <el-button
            v-show="_SHOWBTN('wzgl-xsxc-jtdt-sh')"
              type="warning"
              class="five"
              @click="check1(scope.row.id)"
              v-if="scope.row.publishStatus === 1"
            >审核</el-button>
            <el-button
             v-show="_SHOWBTN('wzgl-xsxc-jtdt-fb')"
              type="success"
              class="five"
              v-else-if="scope.row.publishStatus === 2"
              @click="publish(scope.row.id)"
            >发布</el-button>
            <el-button
            v-show="_SHOWBTN('wzgl-xsxc-jtdt-xg')"
              type="primary"
              class="five"
              v-else-if="scope.row.publishStatus === 3"
              @click="edit(scope.row.id)"
            >编辑</el-button>
            <!-- <el-button class="six" v-else-if="scope.row.publishStatus === 4"></el-button> -->

            <SingleDeletion
            showBetCode="wzgl-xsxc-jtdt-sc"
              :clearOne="clearOne"
              :id="scope.row.id"
              v-if="scope.row.publishStatus !== 1"
            ></SingleDeletion>
          </template>
        </el-table-column>
      </el-table>
      <div class="fenye">
         <Pagination :total="total" :params="params" :get="get1"></Pagination>
      </div>
      <!-- 集团动态查看 -->

      <el-dialog title="集团动态查看" :visible.sync="look">
        <div class="text">
          <h3>{{msg.title}}</h3>
          <div class="source">
            <span class="third" v-if="this.msg.length">来源：{{this.msg.source}}</span>
            <span class="si" v-if="this.msg.length">|</span>
            <span>发布时间：{{this.msg.publishTime}}</span>
          </div>
          <div class="xh"></div>
          <div class="second1 ql-container ql-snow">
            <p class="textone ql-editor" v-html="this.msg.context"></p>
            <p class="textone ql-editor" v-html="this.msg.content"></p>
          </div>
          <div class="comments" v-if="this.msg.publishStatus!==1">
            <span slot="footer" class="dialog-footer">
              <div class="text-input">
                <div class="title">领导批示</div>
                <div class="result">
                  <div v-for="item in result" :key="item.id">
                    <span class="time">{{item.opTime}}</span>
                    <span class="name">{{item.opId}}</span>
                    <span class="text-1">审批结果：</span>
                    <span class="text-2" v-if="item.status===2">审核通过</span>
                    <span class="text-2" v-else>审核驳回</span>
                    <span class="text-3">审批意见：</span>
                    <span class="text-4">{{item.opinion}}</span>
                  </div>
                </div>
              </div>
            </span>
          </div>
        </div>
      </el-dialog>
      <!--集团动态审核 -->
      <el-dialog title="集团动态审核" :visible.sync="check">
        <div class="text">
          <h3>{{msg.title}}</h3>
          <div class="source">
            <span class="third" v-if="this.msg.length">来源：{{this.msg.source}}</span>
            <span class="si" v-if="this.msg.length">|</span>
            <span>发布时间：{{this.msg.publishTime}}</span>
          </div>
          <div class="xh"></div>
          <div class="second1 ql-container ql-snow">
            <p class="textone ql-editor" v-html="this.msg.context"></p>
            <p class="textone ql-editor" v-html="this.msg.content"></p>
          </div>
          <div class="comments">
            <div class="comments3">审核意见</div>

            <el-input type="textarea" v-model="input" placeholder="填写信息受理意见，打回时必填。"></el-input>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button type="danger" @click="repulse" class="repulse">打回</el-button>
          <el-button type="primary" @click="pass" class="pass">通过</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import SingleDeletion from "@/components/Popup/SingleDeletion.vue";
import Pagination from "@/components/Popup/Pagination.vue";
export default {
  components: {
    SingleDeletion,
     Pagination,
  },
  data() {
    return {
      msg: [],
      show: false,
      look: false,
      check: false,
      page: "",
      size: "",
      // 审核结果
      result: "",

      params: {
        endTime: "",
         pageNum: this.$store.state.PortalManagement.pageNum,
        pageSize: this.$store.state.PortalManagement.pageSize,
        publishStatus: "",
        relation: "",
        startTime: "",
        title: "",
      },
      id: 0,
      page: 1,
      size: 10,
      // 表格列表
      tableList: [],
      // 总条数
      total: 0,
      // 时间选择
      value1: "",
      // 专题列表
      list: [],
      // 所属专题
      result: [],
      value4: "",
      // 审核意见
      input: "",
      input1: "",
      input2: "",
      // 请选择
      value: "",
      value2: "",
      value3: true,
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: 1,
          label: "待审核",
        },
        {
          value: 2,
          label: "待发布",
        },
        {
          value: 4,
          label: "已发布",
        },
        {
          value: 3,
          label: "被退回",
        },
      ],
    };
  },
  created() {
    this.get();
    this.get1();
  },
  methods: {
    //获取专题列表
    get() {
      this.Api.getSpecial().then((res) => {
        if (res.code == 0) {
          this.list = res.data;
        }
      });
    },
    //获取集团分类列表
    get1() {
      this.Api.getGroup(this.params).then((res) => {
        if (res.code == 0) {
          console.log(res);
          this.tableList = res.data.records;
          this.tableList.map((item) => {
            if (item.publishStatus == 5) {
              this.$set(item, "isTrue", true);
            } else if (item.publishStatus == 1) {
              this.$set(item, "isTrue", false);
            }
          });

          this.total = res.data.total;
        }
      });
    },
    // // 分页
    // //数据条数发生变化
    // handleSizeChange(newSize) {
    //   this.size = newSize;
    //   if (
    //     this.value == "" &&
    //     this.input1 == "" &&
    //     this.value4 == "" &&
    //     this.value1 == ""
    //   ) {
    //     this.get1();
    //   } else {
    //     this.search();
    //   }
    // },
    // //翻页触发
    // handleCurrentChange(currPage) {
    //   this.page = currPage;
    //   if (
    //     this.value == "" &&
    //     this.input1 == "" &&
    //     this.value4 == "" &&
    //     this.value1 == ""
    //   ) {
    //     this.get1();
    //   } else {
    //     this.search();
    //   }
    // },
    // 搜索
    search() {
      var dateTime = this.value1;
      // 开始时间
      var startDate = "";
      // 结束时间
      var endDate = "";
      if (dateTime != null && dateTime != "" && dateTime != undefined) {
        startDate = this.value1[0];
        endDate = this.value1[1];
      }
      this.Api.groupSearch({
        endTime: endDate,
        pageNum: this.page,
        startTime: startDate,
        publishStatus: this.value,
        relation: this.value4,
        title: this.input1,
        pageSize: this.size,
      }).then((res) => {
        console.log(res);
        this.tableList = res.data.records;
        this.total = res.data.total;
      });
    },
    reset() {
      (this.value1 = ""),
        (this.input1 = ""),
        (this.value = ""),
        (this.value4 = ""),
        this.params={},
        this.params={
         endTime: "",
        pageNum: 1,
        pageSize: 10,
        publishStatus: "",
        relation: "",
        startTime: "",
        title: "",
        },
        this.get1();
    },
    changeCellStyle(row, column, rowIndex, columnIndex) {
      if (row.column.label === "标题") {
        return "padding-left: 35px"; // 修改的样式
      } else {
        return "";
      }
    },
    rowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0 && columnIndex === 1) {
        //指定坐标
        return "padding-left:35px";
      } else {
        return "";
      }
    },
    // 新建
    add() {
      this.$router.push({name:"GroupXj"});
    },
    // 编辑
    edit(id) {
      this.$router.push({ name: "GroupBj", query: { id: id } });
    },
    // 查看
    look1(id) {
      this.look = true;
      this.Api.groupEdit({ id: id }).then((res) => {
        this.msg = res.data;
        if (this.publishStatus == 2) {
          this.result = "审核通过";
        } else {
          this.result = "审核不通过";
        }
        console.log(this.msg);
      });
      // 审批意见
      this.Api.reviewAudit2({
        bussGroup: "wzgl-xsxc-jtdt",
        bussId: id,
        pageNum: "1",
        pageSize: "10",
      }).then((res) => {
        console.log(res);
        this.result = res.data.records;
        console.log(this.result);
      });
    },

    // 审核
    check1(id) {
      this.look1(id);
      this.look = false;
      this.check = true;
    },
    // 通过
    pass() {
      console.log("通过");
      this.check = false;
      this.Api.reviewAudit({
        auditContext: this.input,
        bussId: this.msg.id,
        publishStatus: 2,
      }).then((res) => {
        this.get1();
      });
    },
    //打回
    repulse() {
      console.log("打回");
      this.Api.reviewAudit({
        auditContext: this.input,
        bussId: this.msg.id,
        publishStatus: 3,
      }).then((res) => {
        if (this.input.trim() == "") {
          alert("请写打回理由");
        } else {
          this.check = false;
          this.get1();
        }
      });
    },
    // 删除
    clearOne(id) {
      let ID = { id: id };
      this.Api.groupDelete(ID).then((res) => {
        if (res.code == 0) {
          this.$message.success("删除成功");
          this.get1();
        } else {
          this.$message.error(res.message);
        }
      });
    },
    //  发布
    publish(id) {
      this.Api.reviewPublish({
        id: id,
      }).then((res) => {
        if (res.code == 0) {
          this.get1();
          this.$message.success("发布成功");
        } else {
          this.$message.error("发布失败");
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
/deep/ .ql-snow {
  border: none !important;
}
/deep/.el-date-editor .el-range-separator {
  padding: 0 5px;
  line-height: 32px;
  width: 6%;
  color: #303133;
}
.top {
  width: 1540px;
  height: 68px;
  line-height: 68px;
  color: #333333;
  font-size: 20px;
  border-bottom: 1px solid #dddddd;
  box-sizing: border-box;
}

.top1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.left {
  display: flex;
  margin-top: 19px;
  align-items: center;
}
.right {
  margin-top: 19px;
}
/deep/.left .el-input__inner {
  width: 154px;
  height: 36px;
}
/deep/.left .el-input {
  width: 154px;
}
.left span {
  height: 36px;
  line-height: 36px;
  font-size: 14px;
  color: #333333;
}
.el-button {
  width: 52px;
  height: 36px;
  padding: 0;
}
.five {
  width: 60px;
  height: 28px;
}
.six {
  width: 60px;
  height: 28px;
  color: white;
  border: none;
}
.first,
.second,
.third {
  margin-right: 20px;
}
/deep/.left .data.el-input__inner {
  width: 350px;
  height: 36px;
}
/deep/.search.el-button {
  margin-left: 20px !important;
}
/deep/.reset.el-button {
  background: #d7dbe0;
}
/deep/ .add.el-button {
  width: 80px;
}
/deep/.el-pagination {
  white-space: nowrap;
  padding: 2px 5px;
  color: #303133;
  font-weight: 700;
  margin-left: 850px;
  margin-top: 46px;
}
/deep/.el-pagination {
  white-space: nowrap;
  padding: 2px 5px;
  color: #303133;
  font-weight: 700;
  margin-left: 850px;
  margin-top: 46px;
}
/deep/.el-pagination__jump {
  margin-left: 0;
  font-weight: 400;
  color: #606266;
}
/deep/.el-dialog__header {
  padding: 20px 20px 10px;
  background: #e6e9ed;
}
/deep/.el-dialog {
  width: 1160px;
  min-height: 886px;
  position: absolute;
  top: -100px;
  left: 450px;
  overflow: auto;
  border-radius: 8px;
}
.text {
  width: 1080px;
  height: 100%;
  cursor: pointer;
  margin-left: 20px;
}
.source {
  text-align: center;
  font-size: 16px;
  color: #999999;
  margin-top: 25px;
  margin-bottom: 30px;
}
.si {
  margin: 0 16px;
}
.third {
  margin: 0;
}
p {
  text-indent: 2em;
  font-size: 16px;
  color: #333333;
  margin-top: 30px;
}
p:nth-child(1) {
  text-indent: 0;
  margin-top: 10px;
}
h3 {
  color: #333333;
  text-align: center;
  font-size: 28px;
}
.second1 {
  width: 1080px;
}
.xh {
  width: 1080px;
  height: 1px;
  background: rgba(232, 232, 232, 1);
}
.comments {
  display: flex;
  margin-top: 33px;
  background: rgba(242, 242, 242, 1);
}
.comments1 {
  width: 80px;
  height: 80px;
  border: 1px solid #dddddd;
  border-right: none;
  padding: 18px 23px;
  box-sizing: border-box;
}
.comments2 {
  width: 1010px;
  padding: 15px 9px;
  border: 1px solid #dddddd;
}
.comments span {
  margin-right: 10px;
}
/deep/.comments .el-textarea__inner {
  border-radius: none;
  width: 1010px;
  height: 80px;
}
.comments3 {
  width: 80px;
  height: 80px;
  border: 1px solid #dddddd;
  border-right: none;
  padding: 18px 18px;
  box-sizing: border-box;
}
/deep/.repulse.el-button {
  width: 80px;
  height: 36px;
}
/deep/.pass.el-button {
  width: 80px;
  height: 36px;
  margin-right: 20px;
}
.fenye {
  display: flex;
  justify-content: flex-end;
}
//成功的样式
.dialog-footer {
  .text-input {
    display: flex;
    .title {
      width: 80px;
      height: 80px;
      font-size: 14px;
      line-height: 22px;
      color: rgba(51, 51, 51, 1);
      background: rgba(242, 242, 242, 1);
      border: 1px solid rgba(221, 221, 221, 1);
      padding: 18px 22px 0px 25px;
      white-space: normal;
    }
    .result {
      width: 1010px;
      height: 80px;
      background: rgba(242, 242, 242, 1);
      border: 1px solid rgba(221, 221, 221, 1);
      padding: 15px 0 0 9px;
      text-align: left;
      overflow: auto;
      span {
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: rgba(51, 51, 51, 1);
        line-height: 22px;
      }
      .time {
        margin-right: 5px;
      }
      .name {
        margin-right: 30px;
      }
      .text-1 {
        margin-right: 5px;
      }
      .text-2 {
        margin-right: 30px;
      }
      .text-3 {
        margin-right: 5px;
      }
    }
  }
}
/deep/tbody {
  tr {
    height: 45px !important;
    td {
      padding: 0px 0 !important;
    }
  }
  tr td:last-child {
    .cell {
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
/deep/tbody {
  tr td:nth-child(2) {
    .cell {
      padding-left: 20px;
    }
  }
}
/deep/.el-button--SingleDeletion {
  width: 60px;
  height: 28px;
  background: #fb363f;
  border-radius: 4px;
  color: white;
  padding: 0;
  margin-left: 10px;
}
</style>